package net.ojbk.study.curriculumDesign.service.cilentservicer.impl;

import net.ojbk.study.curriculumDesign.beans.cilentservicer.Chat;
import net.ojbk.study.curriculumDesign.beans.cilentservicer.ChatMessage;
import net.ojbk.study.curriculumDesign.beans.cilentservicer.ChatSystem;
import net.ojbk.study.curriculumDesign.beans.cilentservicer.Servicer;
import net.ojbk.study.curriculumDesign.service.cilentservicer.IServicerCommService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * User: twobox
 * Date: 2019/1/9
 * Time: 12:34
 * Description: No Description
 */
@Service("servicerCommService")
public class ServicerCommServiceImpl implements IServicerCommService {
    @Autowired
    @Qualifier("chatSystem")
    ChatSystem chatSystem;

    /**
     * 一个客服接入一个通讯
     *
     * @param servicer
     * @param chat
     */
    @Override
    public void joinChat(Servicer servicer, Chat chat) {
        // chat操作
//        chat.joinServicer(servicer);
        // 客服中心
//        servicer.joinChat(chat);
        // 客服对象 (集成上面两个操作)
        System.out.println("servicerCommService的chatSystem：" + chatSystem);
        chatSystem.servicerJoinChat(servicer, chat);
    }

    /**
     * 获取该会话的，客服新消息
     *
     * @param chat
     * @return
     */
    @Override
    public ChatMessage getNewMsg(Chat chat) throws Exception {
        return chat.getServicerNewMsgList();
    }

    /**
     * 需求：一个客服，给一个用户的会话（其实前期设计的时候应该给User也包装下），发送一条消息
     *
     * @param servicer    客服
     * @param chat        用户的会话
     * @param chatMessage 消息
     */
    @Override
    public void sendMsg(Servicer servicer, Chat chat, ChatMessage chatMessage) throws Exception {
        servicer.sendMsgToUserChat(chat, chatMessage);
    }

    /**
     * 需求：一个客服，断开 一个用户，的会话
     *
     * @param servicer
     * @param chat     用户的对话（理应是一个上层抽象的会话对象）
     */
    @Override
    public void catChat(Servicer servicer, Chat chat) throws Exception {
        servicer.cutChat(chat);
    }
}
